<?php
/**
 * 广告信息控制器
 *
 * @package     Include  (controller)
 * @author      hary <hary@taomee.com>
 * @version     $ID 2010-3-31 $
 */
class Admin_purpose extends Controller
{
	private $result;

	/**
	 * 构造函数
	 */
	function __construct()
	{
		parent::__construct();

		$this->loadModel('ads_purpose_model');

		$this->loadClass('cache');

	}

	/**
	 * 默认执行方法
	 *
	 * @return
	 */
	function index()
	{
		$this->getpurposes();
	}

	/**
	 * 保存purpose
	 * @return max
	 */
	function savepurpose(){

		$purpose = $this->in_var;

		if(!empty($purpose['pp_id']))
		{
			$flag = $this->ads_purpose_model->changePurpose($purpose);
		}
		else
		{
			$flag = $this->ads_purpose_model->addPurpose($purpose);
		}
		
		if($flag===false)
		{
			exit("error");
		}
		else
		{
			$purposes = $this->ads_purpose_model->getPurposesByKeywords();
			$this->cache->setCache("ads","purposes",$purposes);
			echo $flag;exit;
		}

	}

	/**
	 * 批量删除purpose
	 * @return max
	 */
	function delpurposes(){

		$ids = $this->in_var['item'];

		$id_ = explode(',',$ids);

		try{
			foreach($id_ as $id)
			{
				$this->ads_purpose_model->delPurposeById($id);
			}
			
			$purposes = $this->ads_purpose_model->getPurposesByKeywords();
			
			if(empty($purposes))
			{
				$this->cache->clearCache("ads","purposes");
			}
			else
			{
				$this->cache->setCache("ads","purposes",$purposes);
			}
		}
		catch(Exception $e)
		{
			exit(json_encode(array('info'=>$this->sys_conf_var['ads']['customer_msg']['purpose']['del_error'],'status'=>false)));
		}

		exit(json_encode(array('info'=>$this->sys_conf_var['ads']['customer_msg']['purpose']['del_success'],'status'=>true)));
	}

}